<template>
  <div>
    <Banner></Banner>
    <div class="classitem">
      <h2>精选好课</h2>
      <ul>
        <li v-for="(item, i) in classes" :key="i">
          <router-link :to="'/details/'+item.id">
            <div class="imgbox">
            <img :src="item.img" alt="" />
          </div>
          <p>{{ item.title }}</p>
          <p>{{ item.views }}人学过</p>
          <span>￥{{ item.prices }}</span>
          </router-link>
        </li>
      </ul>
      <div class="more el-icon-refresh" @click="more">
        换一批
      </div>
    </div>
  </div>
</template>

<script>
import Banner from "./Banner";
import { getClass } from "../../api/course";
export default {
  data() {
    return {
      classes: [],
      page: 1,
    };
  },
  components: {
    Banner,
  },
  mounted() {
    this.getclass();
  },
  methods: {
    getclass() {
      getClass(this.page).then((res) => {
        if (res.data.length == 0) {
          this.page=1
          this.getclass()
        } else {
          this.classes = res.data;
          this.page++;
        }
      });
      console.log(this.classes);
    },
    more() {
      this.getclass(this.page);
    },
  },
};
</script>

<style scoped>
.classitem {
  background-color: #ffffff;
}
h2 {
  line-height: 0.6rem;
  font-size: 0.32rem;
  font-weight: bold;
  margin-left: 0.2rem;
  padding-top: 0.2rem;
}
ul {
  padding: 0.2rem;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
}
li {
  width: 3.46rem;
  margin-bottom: 0.2rem;
}
li img {
  width: 100%;
  height: 1.88rem;
}
li p {
  font-size: 0.26rem;
  line-height: 0.48rem;
}
span {
  line-height: 0.4rem;
  color: #ee6848;
}
.more {
  height: 0.66rem;
  font-size: 0.32rem;
  text-align: center;
  width: 100%;
}
</style>
